<?php
class WidgetController extends ModuleAppController {
	var $name = 'Widget';
	var $uses = array();

	/**
	 * Module Name: ProductTypeCol
	 * Get all product type in tblProductTypes by parentID;
	 * View: Col
	 * @param integer $id
	 */
	function product_types_col() {
		$this->layout = null;
		$this->loadModel('ProductType');

		if(isset($this->params['parent']) ) {
			$id = $this->params['parent'];
		}
		if(isset($id)) {
			$this->set('productTypes', $this->ProductType->all($id));
		} else {
			$this->set('productTypes', $this->ProductType->all());
		}

		$this->render();
	}

	/**
	 * Module Name: ProductType
	 * Get all product type in tblProductTypes by parentID;
	 * @param integer $id
	 */
	function product_types() {
		$this->layout = null;
		$this->loadModel('ProductType');
		$this->loadModel('Product');
		$lang = Configure::read('Config.language');

		$category = $this->ProductType->find('all', array(
			'conditions' =>  array('ProductType.status' => 1, 'ProductType.parent' => 0),
			'order'      =>  'ProductType.sort'
		));

		if (!empty($category)) {
                    for ($i = 0; $i < count($category); $i++) {
                        $category[$i]['sub'] = $this->ProductType->find('all', array(
                                        'conditions' =>  array('ProductType.status' => 1, 'ProductType.parent' => $category[$i]['ProductType']['id']),
                                        'order'		 =>  'ProductType.sort'
                        ));
                    }
		}

		$this->set('category',$category);
		$this->set('lang',$lang);

		$this->render();
	}

	function promotion() {
		$this->layout = null;

		$this->loadModel('News');

		$lang = Configure::read('Config.language');

		$news = $this->News->find('first', array(
			'conditions' =>  array('News.status' => 1),
			'order'		 =>  'News.date desc',
			'fields' 	 =>  array('News.title_'.$lang,'News.description_'.$lang,'News.image','News.id')
		));

		$this->set('news',$news);
		$this->set('lang',$lang);

		$this->render();
	}


	function inside_banner(){
		$this->loadModel('Picture');
		$advertise = $this->Picture->find('all',array(
				'conditions' => array(
					'Picture.kind' => 3
				),
				'order' => 'rand()',
				'limit' => 3
		));

		$this->set('advertises', $advertise);
		$this->render();
	}



	function brand_list(){
		$this->loadModel('Picture');
		$brand = $this->Picture->find('all',array(
				'conditions' => array(
					'Picture.kind' => 2,
					'Picture.status' => 1
				),
				'order' => 'Picture.sortby asc'
			));
		$this->set('brand', $brand);
		$this->render();
	}

	function other_products(){
		$this->loadModel('Product');
		$this->loadModel('ProductType');
		$lang = Configure::read('Config.language');
		if (isset($this->params['id'])) {
			$products = $this->Product->find('all',array(
				'conditions' => array(
					'Product.id !=' => $this->params['id'],
					'Product.type'  => $this->params['type']
				),
				'order' => 'rand()',
				'limit' => 6
			));
		}
		$this->set('other_products',$products);
		$this->set('lang',$lang);
		$this->render();
	}

	function hit_counter() {
		$this->loadModel('Hitcounter');
		$hitcounter = $this->Hitcounter->find('count');
		$this->set('hitcounter', $hitcounter);
		echo $hitcounter;
	}

	function left_ad() {
		$this->loadModel('Picture');
		$advertise = $this->Picture->find('all',array(
				'conditions' => array(
					'Picture.kind' => 4,
					'Picture.menu' => 'left'
				),
				'order' => 'Picture.sortby asc'
			));
		$this->set('ad', $advertise);
		$this->render();
	}
        
        function hotline() {
            $this->loadModel('Setting');
            $tmp = $this->Setting->findByParam('HOTLINE');
            echo ($tmp['Setting']['value']);
        }
        
        function support() {
            $this->loadModel('Setting');
            $tmp = $this->Setting->findByParam('YAHOO_MESSENGER_ACC');
            $this->set('yahoo', $tmp['Setting']['value']);
            $tmp2 = $this->Setting->findByParam('SKYPE_MESSENGER_ACCOUNT');
            $this->set('skype', $tmp['Setting']['value']);
            $this->render();
        }
}